import os
import sys

try:
    from pysnmp.entity.rfc3413.oneliner import cmdgen
except:
    print "Couldn't load required modules. You probably need to install it with:"
    sys.exit('sudo apt-get install python-pyrrd python-pysnmp4')

def get(oid):
    errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().getCmd(
                                                cmdgen.CommunityData('test-agent', 'public'),
                                                cmdgen.UdpTransportTarget(('192.168.1.1', 161)),
                                                oid,
                                                (('SNMPv2-MIB', 'sysObjectID'), 0)
                                                )
    if errorIndication:
        print errorIndication
    else:
        if errorStatus:
            print '%s at %s\n' % ( errorStatus.prettyPrint(), errorIndex and varBinds[int(errorIndex)-1] or '?')
        else:
            for name, val in varBinds:
                if name == oid:
                    return val


